<template>
	<view>
		<view class="body" >
			<template>
				<m-position listType="1" :positions="list" @click="positionDetail"></m-position>
			</template>
			<view class="load-more-box">
				<uni-load-more v-if="status == '请求中'" status="正在加载..." :showIcon="true"></uni-load-more>
				<uni-load-more v-if="status == '没有更多'" status="没有更多了" :showIcon="false"></uni-load-more>
				<uni-load-more v-if="status == '暂无数据'" status="暂无数据" :showIcon="false"></uni-load-more>
				<uni-load-more v-if="status == '请求失败'" status="加载失败，点我重试" :showIcon="false" @click="reLoad"></uni-load-more>
			</view>
			<view class="btnBox"><image class="addBtn" @click="toPublish" src="../../static/icon/add.png"></view>
		</view>
		
	</view>
</template>

<script>
import { mapState, mapMutations, mapGetters } from 'vuex';
import mPosition from '@/components/yzb/yzb-position-publish.vue';
export default {
	components: {
		mPosition,
	},
	computed: {
		...mapState(['userInfo']),
		...mapGetters(['hasLogin'])
	},
	data() {
		return {
			
			list: [],
			status: '',
			query: {
				current: 1,
				number: 10,
				positionType: 0,
				keyword: '',
				postId: '',
				industryId: '',
				salary: '',
				nature: ''
			},

		};
	},
	created() {
	},
	
	onLoad(options) {
	},
	onShow() {
		this.query.current = 1;
		this.list = [];
		this.getPositionList();
		
	},

	onPullDownRefresh() {
		this.query.current = 1;
		this.getPositionList();
	},

	onReachBottom() {
		this.getPositionList('add');
	},

	methods: {

		async getPositionList(type = 'refresh', pulldown = false) {
			this.status = '请求中';
			if (type == 'refresh') {
				this.query.current = 1;
			} else {
				this.query.current++;
			}
			let data = await this.$apis.businessSaveList(this.query);
			if (data) {
				if (type == 'refresh') {
					this.list = [];
				}
				if (pulldown) {
					uni.stopPullDownRefresh();
				}
			
				this.list = this.list.concat(data || []);
				this.changeStatus(data);
			}
		},

		toPublish(){
			console.log("toPublish");
			this.$mRouter.push({
				route: this.$mRoutesConfig.publishJob
			});
		},

		// 修改请求状态
		changeStatus(data) {
			if (this.list.length === 0) {
				this.status = '暂无数据';
			} else if (this.query.number > data.length) {
				this.status = '没有更多';
			} else {
				this.status = '请求更多';
			}
		},

		positionDetail(item) {
			this.$mRouter.push({
				route: this.$mRoutesConfig.positionDetail,
				query: {
					id: item.id
				}
			});
					
		},
	}
};
</script>
<style lang="scss">
	.body{
		margin-bottom:140rpx;
	}
	.btnBox{
		background-color: white;
		position:fixed;
		width:100%;
		bottom:0;
	}
.addBtn{
	
	display: block;
	margin:20rpx auto;
	width:100rpx;
	height:100rpx;
}
</style>
